???.install   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
nc 2
nop 2
dl 0
loc 20
ccs 10
cts 10
cp 1
cc 3
crap 3
rs 9.4285
1
import filter from 'feathers-query-filters'
2
import {matcher} from 'feathers-commons/lib/utils'
3
4
import aliasesMixinMaker from './aliases'
5
import Syncer from './syncer'
6
import syncerMixin from './mixin'
7
8 8
const defaults = {
9
	aliases: false,
10
	driver: Syncer,
11
	filter,
12
	idField: 'id',
13
	matcher
14
}
15
16
export default {
17
	/**
18
	 * Install to vue
19
	 *
20
	 * @function
21
	 * @param {Vue} Vue - Vue
22
	 * @param {Object} options - Options
23
	 * @param {Function} [options.aliases] - Aliases to enable
24
	 * @param {Function} [options.driver] - Custom driver to use
25
	 * @param {Function} [options.filter] - Query filter parser
26
	 * @param {Object} [options.feathers] - Feathers client
27
	 * @param {string} [options.idField] - Default ID field
28
	 * @param {Function} [options.matcher] - Matcher creator
29
	 */
30
	install(Vue, options = {}) {
31 36
		const extend = Vue.util.extend
32
		// Vue 2.0 has util.toObject, but 1.0 doesn't
33 36
		options = extend(extend({}, defaults), options)
34
35 36
		if (!('feathers' in options)) {
36 1
			throw new Error('No feathers instance set in options')
37
		}
38
39 35
		Vue.$syncer = options
40 35
		Vue.prototype.$feathers = options.feathers
41
42 35
		Vue.mixin(syncerMixin(Vue))
43
		// Mixin handling
44 35
		Vue.config.optionMergeStrategies.sync = Vue.config.optionMergeStrategies.props
45
46 35
		if (options.aliases) {
47 1
			Vue.mixin(aliasesMixinMaker(options.aliases))
48
		}
49
	}
50
}
51